﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using CrusadeGmTool.Net.IO;

namespace CrusadeGmTool.Net
{
    public interface INetworkContext : INotifyPropertyChanged
    {
        long BytesReceived{get;}
        long BytesSent { get; }
        bool Connected { get; }
        bool Connecting { get; }
        bool DecompressionEnabled { get; }
        bool LogPackets { get; set; }
        System.Net.IPAddress ServerAddress { get; }
        event EventHandler ConnectedChanged;

        bool Connect(string ipAdressorHostName, int port);
        void Disconnect();
        
        PacketHandler GetExtendedHandler(byte cmd, short subCmd);
        PacketHandler GetHandler(byte[] buffer, int index, ref int packetLength, ref bool extended);

        void Register(int id, string name, int? length, Action<PacketReader> receiveAction);
        void Register(int id, string name, int? length, bool compressed, Action<PacketReader> receiveAction);
        void RegisterExtended(int extendedId, int subId, string name, int? length, Action<PacketReader> receiveAction);

        bool Send(Packet packet);
        bool Send(byte[] buffer, int offset, int length);
    }
}
